<?php
/*
 * 生成URL
 * @package
 * @author     Mark
 * @copyright  Copyright (c) 2013 ixdcw team
 * @version    $Id: 7c8e5817d19788a0fca4c560f98df6f6b9fc501f $
 */
/**
 * Class U
 */
class U {

	const DOMAIN_IMG0     = 'img0';
	const DOMAIN_IMG1     = 'img1';

	private static function _getSubDomains() {
		$domain = $GLOBALS['CFG']['domain']; // ixdcw.com
		return array(
			self::DOMAIN_IMG0     => "http://img0.{$domain}/",
			self::DOMAIN_IMG1     => "http://img1.{$domain}/",
		);
	}

	private static function _getRealpaths() {
		return $GLOBALS['CFG']['realPaths'];
	}


	/**
	 * 获得模块链接
	 * @param $param  可以是模块的ID, 模块的名称
	 */
	public static function module($param) {
		$MODULE = $GLOBALS['MODULE'];
		if (is_numeric($param)) {
			$param = intval($param);
			if (isset($MODULE[$param])) {
				return $MODULE[$param]['linkurl'];
			}
		} else {
			foreach ($MODULE as $v) {
				if ($v['module'] === $param) {
					return $v['linkurl'];
				}
			}
		}
		return SITE_URL;
	}

	/**
	 * 拼合信息类的链接地址
	 * @param $moduleid
	 * @param $infoLinkurl
	 * @return mixed
	 */
	public static function combine($moduleid, $infoLinkurl) {
		return self::module($moduleid) . $infoLinkurl;
	}

	/**
	 * 生成完整的域名
	 * @param $param 参数值来自于类中定义的函数.
	 */
	public static function domain($param = '') {
		$subDomains = self::_getSubDomains();
		if (!empty($param) && isset($subDomains[$param])) {
			return $subDomains[$param];
		} else {
			return SITE_URL;
		}
	}

	/**
	 * 返回域名绑定地址的真实位置, 支持IMG0, IMG1, static, homepage
	 * @param $param
	 * @return string
	 */
	public static function realpath($param) {
		$realPaths = self::_getRealpaths();
		if (!array_key_exists($param, $realPaths)) {
			return '';
		} else {
			return $realPaths[$param];
		}
	}

}